#!/bin/bash

[ -f /opt/factory_test/scripts_lib/common.sh ] && source /opt/factory_test/scripts_lib/common.sh

ARG=$1
if [ $ARG == "stop" ];then
	man_kill $0 modetest
	exit 0
fi

titel "HDMI RESOLUTION"
for i in $HDMI_CONNECTOR_LIST
do
	sum=$sum"|${i}"
done
modetest -M rockchip -c | grep -E "#*driver*$sum"


titel "HDMMI MODETEST"

rm -rf /tmp/.HDMI
MODE_LIST=$(modetest -M rockchip -c | grep -E "#*driver*$sum" | awk -F " " '{print $1}')
for i in $MODE_LIST
do
	if echo "$i" | grep -vq "#";then
		for ii in $HDMI_CONNECTOR_LIST
		do
			HDMI_CONNECTOR=$(cat /sys/kernel/debug/dri/0/state | grep "$ii" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}')
			if [ $i == $HDMI_CONNECTOR ];then
				echo "Connector: $ii"
				break
			fi
		done
	else
		echo "Mode: $i"
		echo "Check HDMI Display, [Enter]/x3 to continue"
		HDMI_MODE=$(echo $i | awk -F " " '{print $1}')
		modetest -M rockchip -s $HDMI_CONNECTOR:$HDMI_MODE -Ftiles
		[ $? != 0 ] &&  echo "[Connector: $HDMI_NAME  Mode: $ii]:ERR Please Check"
	fi
done

man_exit 2
